﻿/// <reference path="../Core.js" />
IM.ColorHelper = {
    Hexch: ["0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "A", "B", "C", "D", "E", "F"],
    HexStr: "0123456789ABCDEF",
    ToHex: function(n) {
        var h, l;
        n = Math.round(n);
        l = n % 16;
        h = Math.floor((n / 16)) % 16;
        return (this.Hexch[h] + this.Hexch[l]);
    },

    RGB2Color: function(r, g, b) {
        var r, g, b;
        return ('#' + this.ToHex(r) + this.ToHex(g) + this.ToHex(b));
    },

    Color2RGB: function(strhex) {
        r = this.HexStr.indexOf(strhex.charAt(1)) * 16 + this.HexStr.indexOf(strhex.charAt(2));
        g = this.HexStr.indexOf(strhex.charAt(3)) * 16 + this.HexStr.indexOf(strhex.charAt(4));
        b = this.HexStr.indexOf(strhex.charAt(5)) * 16 + this.HexStr.indexOf(strhex.charAt(6));
        return (r + "," + g + "," + b);
    }
}
